var t = getApp(), a = require("../../../utils/themeSkin/skinBehavior");

Page({
    behaviors: [ a ],
    data: {
        activityName: "",
        average: "",
        personNumber: "",
        credit1: 0,
        integral: "",
        clicktag: 0
    },
    onLoad: function(t) {
        this._getIntegral();
        try {
            var a = wx.getStorageSync("integral");
            a && (this.setData({
                integral: a
            }), this.data.integral && wx.setNavigationBarTitle({
                title: "发起" + this.data.integral + "赠送"
            }));
        } catch (t) {}
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    activityNameinp: function(t) {
        var a = t.detail.value;
        this.setData({
            activityName: a
        });
    },
    averageinp: function(t) {
        var a = t.detail.value;
        this.setData({
            average: a
        });
    },
    personNumberinp: function(t) {
        var a = t.detail.value;
        this.setData({
            personNumber: a
        });
    },
    _getIntegral: function() {
        var a = this, e = t.getNetAddresss("finance.point-page.index");
        t._getNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (a.setData({
                    credit1: e.data.credit1
                }), wx.setNavigationBarColor({
                    frontColor: "#ffffff",
                    backgroundColor: a.data.themeBaseColor,
                    animation: {
                        duration: 400,
                        timingFunc: "easeIn"
                    }
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    createActivity: function() {
        if (this.data.activityName && this.data.average && this.data.personNumber) {
            if (this.checkScore()) {
                var a = this;
                if (0 === this.data.clicktag) {
                    a.setData({
                        clicktag: 1
                    });
                    var e = t.getNetAddresss("plugin.point-activity.Frontend.Modules.Activity.Controllers.create.index");
                    t._postNetWork({
                        url: e,
                        showToastIn: !1,
                        data: {
                            name: a.data.activityName,
                            average: a.data.average,
                            total: a.data.personNumber
                        },
                        success: function(t) {
                            var e = t.data;
                            1 == e.result ? (a.setData({
                                activityName: "",
                                average: "",
                                personNumber: ""
                            }), wx.showToast({
                                icon: "none",
                                title: "创建成功",
                                duration: 1500
                            }), setTimeout(function() {
                                a.setData({
                                    clicktag: 0
                                }), wx.navigateBack({
                                    delta: 1
                                });
                            }, 1e3)) : wx.showToast({
                                icon: "none",
                                title: e.msg,
                                duration: 1500
                            });
                        },
                        fail: function(t) {}
                    });
                }
            }
        } else wx.showToast({
            icon: "none",
            title: "信息不能为空",
            duration: 1500
        });
    },
    checkScore: function() {
        return !(Number(this.data.average) * Number(this.data.personNumber) > Number(this.data.credit1)) || (wx.showToast({
            icon: "none",
            title: "您的" + (this.data.integral ? this.data.integral : "积分") + "不够",
            duration: 1500
        }), !1);
    }
});